package org.emet.dao;

import org.apache.commons.lang.StringUtils;
import org.emet.entity.biz.Freezer;
import org.emet.jee.core.dao.Page;
import org.emet.jee.core.dao.arch.ArchDataSourceBaseDao;
import org.emet.service.dto.FreezerBoxCriteria;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

@Repository
public class FreezerBoxDao extends ArchDataSourceBaseDao<Freezer, Long> {
	public Page<Freezer> search(Page<Freezer> page, FreezerBoxCriteria criteria) {
		Criteria c = getSession().createCriteria(Freezer.class);
		NonEmptyValueHashMap<String, Object> propertyNameValues = new NonEmptyValueHashMap<String, Object>();
		propertyNameValues.put("name", criteria.getName());
		propertyNameValues.put("status", criteria.getStatus());
		if (!StringUtils.isBlank(criteria.getRemark())) {
			c.add(Restrictions.like("remark", "%" + criteria.getRemark() + "%"));
		}
		c.add(Restrictions.allEq(propertyNameValues));
		page.setOrderBy("id");
		page.setOrder("desc");
		return findPage(page, c);
	}
}
